using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using MULENetworking;
using System.Drawing;

namespace MULEServer
{
    public class ServerMap : IMap
    {
        int horizontal;
        int vertical;

        private IMapSquare[,] map;

        public ServerMap()
        {
            map = new IMapSquare[9,5];

            horizontal = 9;
            vertical = 5;

            
            map[4, 0] = new ServerMapSquare(new Point(400, 0), "food", 0, "empty");
            map[4, 1] = new ServerMapSquare(new Point(400, 100), "food", 0, "empty");
            map[4, 3] = new ServerMapSquare(new Point(400, 300), "food", 0, "empty");
            map[4, 4] = new ServerMapSquare(new Point(400, 400), "food", 0, "empty");

            IMapSquare store = new ServerMapSquare(new Point(400, 200), "store", 0, "empty");
            map[4,2] = store;
            MountainPlacement(20);
            for (int x = 0; x < 9; x++)
            {
                for (int y = 0; y < 5; y++)
                {
                    if (map[x,y] == null)
                        map[x, y] = new ServerMapSquare(new Point(x * 100, y * 100), "energy", 0, "empty");
                }
            }
         }

        #region IMap Members

        public IMapSquare[,] Squares
        {
            get
            {
                return map;
            }
            set
            {
                map = value;
            }
        }

        #endregion
        

        private void MountainPlacement(int numMountains)
        {
            int x = 0;
            int y = 0;
            Random rand = new Random();
            int totMountains = 0;
            int mountainsToPlace;
            while(totMountains < numMountains)
            {
                x = rand.Next(0, horizontal);
                y = rand.Next(0, vertical);

                if (map[x,y] == null)
                {
                    mountainsToPlace = rand.Next(1, 4);
                    totMountains += mountainsToPlace;
                    if (totMountains > numMountains)
                    {
                        mountainsToPlace = totMountains - numMountains;
                    }
                    map[x,y] = new ServerMapSquare(new Point(x * 100, y * 100), "smithore", mountainsToPlace, "empty");
                }
            }
        }
    }
}

